package com.rd.student.dashuju.wangbo.day0728;

import java.io.*;
import java.util.Random;
import java.util.Scanner;

public class TestRandom3 {

    public static void main(String[] args) throws Exception{
        File file = new File("all.txt");
        InputStream is = new FileInputStream(file);
        String s = null;
        while (true){
            byte[] arr = new byte[(int) file.length()];
            int len = is.read(arr);
            if (len == -1){
                break;
            }
            s = new String(arr);
            System.out.println(s);
        }
        String[] strArr =s.split("、");
        System.out.println("请输入人数");
        Scanner scanner = new Scanner(System.in);
        int number = scanner.nextInt();
        if (number>= strArr.length) {
            System.out.println(s);
            return;
        }

        Random random = new Random();
        FileOutputStream fos = new FileOutputStream("random.txt");
        PrintStream ps = new PrintStream(fos);

        for (int i = 0; i < number; i++) {
            int n = random.nextInt(strArr.length);
            System.out.println(strArr[n]);
            ps.println(strArr[n]);
        }

        ps.close();

    }

}
